package com.ithzl.capacity.controller;

import com.ithzl.capacity.mapper.EntryFormMapper;
import com.ithzl.capacity.pojo.EntryForm;
import com.ithzl.capacity.pojo.RESTful.RestBean;
import com.ithzl.capacity.pojo.dto.ReviewPageDTO;
import com.ithzl.capacity.pojo.dto.WorksBriefDTO;
import com.ithzl.capacity.service.EntryFormService;
import com.ithzl.capacity.service.ReviewService;
import jakarta.servlet.http.HttpSession;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/review")
public class ReviewController {

    @Autowired
    ReviewService reviewService;

    @Autowired
    EntryFormService entryFormService;

    /**
     * 获取作品简要信息，按页
     * @param reviewPageDTO
     * @return
     */
    @PostMapping("/getList")
    public RestBean selectReviewList(ReviewPageDTO reviewPageDTO){

        List<WorksBriefDTO> worksBriefDTOList=reviewService.selectWorksBrief(reviewPageDTO);
        return RestBean.succeed(worksBriefDTOList);
    }

    /**
     * 获取作品详情
     * @param entryFormId
     * @return
     */
    @PostMapping("/getEntryForm")
    public RestBean getEntryForm(@Param("entryFormId") int entryFormId){
        EntryForm entryForm=entryFormService.selectEntryForm(entryFormId);
        return RestBean.succeed(entryForm);
    }

    /**
     * 评委审评作品
     * @param entryFormId
     * @param opinion
     * @param score
     * @return
     */
    @PostMapping("/review")
    public RestBean review(@Param("entryFormId") int entryFormId,
                           @Param("opinion") String opinion,
                           @Param("score") double score,
                           HttpSession session){
        reviewService.review(entryFormId,opinion,score,session);
        return RestBean.succeed();

    }

}
